package daily_exercise;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class compareVersion {

    public static int compareVersion(String s1, String s2){
        if (s1 == null || s1.length() == 0 || s2 == null || s2.length() == 0){
            return 0;
        }
        String[] ss1 = s1.split("\\.");
        String[] ss2 = s2.split("\\.");
        int i = 0;
        while(i < ss1.length && i < ss2.length){
            if (Integer.parseInt(ss1[i]) > Integer.parseInt(ss2[i])){
                return 1;
            } else if(Integer.parseInt(ss1[i]) < Integer.parseInt(ss2[i])){
                return -1;
            }
            i++;
        }
        while(i < ss1.length){
            if (Integer.parseInt(ss1[i]) > 0){
                return 1;
            }
            i++;
        }
        while(i < ss2.length){
            if (Integer.parseInt(ss2[i]) > 0){
                return -1;
            }
            i++;
        }
        return 0;
    }

    public static void main(String[] args) {
        String s1 = "1.2.3";
        String s2 ="1.2.1";
        System.out.println(compareVersion(s1, s2));
        System.out.println(compareVersion("1.0", "1.1"));

        Map<Integer,Integer> map = new HashMap<>();
        List<Integer> l = new ArrayList<>();
    }
}
